<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$rows['id'] = '7';
$rows['openid'] = 'o0SKv4q3A9wijbd71F5GYq-_bNVQ';
$token = '9dbfcb94db03d97f2ac1d616b685c5e416e2d503';
$data= json_encode($rows);
$redis->setex($token, 86400*30, $data);
exit;
$blog = $redis->get('redisrow');
//如果$blog数组为空，则去数据库中查询，并加入到redis中
if (empty($blog)) {
   // echo "mysql";
// Connect mysql server
    $mysql = new PDO("mysql:host=localhost;dbname=test", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    $rs    = $mysql->query("select * from tbl_user");
//$row = $rs -> fetch();
    $i = 0;
    while ($row = $rs->fetch()) {
        $rows[$i]['username'] = $row['user_name'];
        $rows[$i]['email']    = $row['email'];
        $i                    = $i + 1;
    }
    echo "mysql<br>";
    print_r($rows);
    $redisrow = json_encode($rows);
    $redis->setex('redisrow', '100', $redisrow); //100秒，
} else {
    echo "redis<br>";
    $redisblog = json_decode($blog,true);
    echo "redis";
    print_r($redisblog);
}
